// main

import { existsSync } from "https://deno.land/std@0.184.0/fs/exists.ts";
import getAllSVGS from "./auto-convert-to-css.ts";

// Learn more at https://deno.land/manual/examples/module_metadata#concepts
if (import.meta.main) {
  if (existsSync("./a8icons.svg")) {
    Deno.removeSync("./a8icons.svg");
  }
  const names = getAllSVGS("./a8icons.svg");
  const readme = `
  .your-class {
    background-image: url("./a8icons.svg#编辑");
    background-repeat: no-repeat;
    background-size: 100px 100px;
    color: #5854a9;
  }
  `;
  console.log(readme);
  console.log("# 可用的id如下:");
  console.log(names.join("\n"));
  console.log("convert icons: " + names.length + " icons");
  if (existsSync("./a8icons.css")) {
    Deno.removeSync("./a8icons.css");
  }
  const cssContents: string[] = [];
  names.forEach((name) => {
    cssContents.push(`.a8icons-${name} {
  background-image: url("./a8icons.svg#${name}");
  background-size: 16px 16px;
}`);
  });
  Deno.writeTextFileSync("./a8icons.css", cssContents.join("\n"));
  console.log("done");
}
